package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.base.KnowledgeDataBaseEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * 知识条目枚举
 *
 * @author ruansicheng
 * @version v1.0
 * @date 2022/06/21 15:37
 * @since v1.0
 */
@Getter
public enum KnowledgeDataEnum {

    // base_info：基本信息
    BASE_INFO(KnowledgeDataBaseEnum.BASE_INFO.getAttr(), "enum.knowledgeDataEnum.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType(), 1),
    // 目录
    CATALOGUE(KnowledgeDataBaseEnum.CATALOGUE.getAttr(), "enum.knowledgeDataEnum.attrName.catalogue_id", "catalogue_id", FieldTypeEnum.SERIALNO.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType(), 0),
    // 标题
    TITLE(KnowledgeDataBaseEnum.TITLE.getAttr(), "enum.knowledgeDataEnum.attrName.title", "title", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9980, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType(), 1),
    // 拓展问法
    EXPAND_CONSULT(KnowledgeDataBaseEnum.EXPAND_CONSULT.getAttr(), "enum.knowledgeDataEnum.attrName.expand_consult", "expandConsult", FieldTypeEnum.OWNERID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9970, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType(), 0),
    // 关键词
    KEYWORDS(KnowledgeDataBaseEnum.KEYWORDS.getAttr(), "enum.knowledgeDataEnum.attrName.keywords", "keywords", FieldTypeEnum.LINK_BUSINESS_MULTI.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType(), 1),
    // 标签
    LABEL(KnowledgeDataBaseEnum.LABEL.getAttr(), "enum.knowledgeDataEnum.attrName.label", "label", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType(), 0),
    // 建议回复
    CONTENT(KnowledgeDataBaseEnum.CONTENT.getAttr(), "enum.knowledgeDataEnum.attrName.content", "content", FieldTypeEnum.NUM.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType(), 0),
    // 附件
    APPENDIX(KnowledgeDataBaseEnum.APPENDIX.getAttr(), "enum.knowledgeDataEnum.attrName.appendix", "appendix", FieldTypeEnum.UPLOAD.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9860, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType(), 1),
    // 其他信息
    OTHER_INFO(KnowledgeDataBaseEnum.OTHER_INFO.getAttr(), "enum.knowledgeDataEnum.attrName.other_info", "otherInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType(), 1),
    // 状态
    STATUS(KnowledgeDataBaseEnum.STATUS.getAttr(), "enum.knowledgeDataEnum.attrName.status", "status", FieldTypeEnum.SINGLE_SUB_FORM.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.EDIT.getCode(), 9880, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType(), 1),
    // 创建人
    CREATOR_ID(KnowledgeDataBaseEnum.CREATOR_ID.getAttr(), "enum.knowledgeDataEnum.attrName.creator_id", "creatorId", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9910, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType(), 1),
    // 创建时间
    ADD_TIME(KnowledgeDataBaseEnum.ADD_TIME.getAttr(), "enum.knowledgeDataEnum.attrName.add_time", "addTime", FieldTypeEnum.COMBO.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9900, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType(), 1),
    // 更新人
    UPDATE_ID(KnowledgeDataBaseEnum.UPDATE_ID.getAttr(), "enum.knowledgeDataEnum.attrName.update_id", "updateId", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9910, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType(), 1),
    // 更新时间
    UPDATE_TIME(KnowledgeDataBaseEnum.UPDATE_TIME.getAttr(), "enum.knowledgeDataEnum.attrName.update_time", "update_time", FieldTypeEnum.TEXTAREA.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9870, 1, 0, ScreenTypeEnum.SCREEN_SHOW.getType(), 1),
    //使用次数
    USAGE_COUNT(KnowledgeDataBaseEnum.USAGE_COUNT.getAttr(), "enum.knowledgeDataEnum.attrName.usage_count", "usageCount", FieldTypeEnum.TEXTAREA.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.NONE.getCode(), 9870, 1, 0, ScreenTypeEnum.SCREEN_SHOW.getType(), 1),
    ;

    /**
     * 英文名称
     */
    private String attr;

    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    /**
     * 是否允许编辑 1：允许 0：不允许
     */
    private Integer editable;

    KnowledgeDataEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                           Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType,
                           Integer editable) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
        this.editable = editable;
    }

    public static String getEsAttr4Keyword(KnowledgeDataEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }

    public static List<String> getNotImportAttrList(int code) {
        return Arrays.asList(KnowledgeDataBaseEnum.CREATOR_ID.getAttr(), KnowledgeDataBaseEnum.UPDATE_ID.getAttr(), KnowledgeDataBaseEnum.LABEL.getAttr(),
                KnowledgeDataBaseEnum.USAGE_COUNT.getAttr(), KnowledgeDataBaseEnum.ADD_TIME.getAttr(), KnowledgeDataBaseEnum.UPDATE_TIME.getAttr(), KnowledgeDataBaseEnum.APPENDIX.getAttr(), KnowledgeDataBaseEnum.BASE_INFO.getAttr(), KnowledgeDataBaseEnum.OTHER_INFO.getAttr());
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }

    public String getI18nAttrName() {
        return attrName;
    }

}
